import React from 'react'
import LocalStorageService from "../../utils/LocalStorageService";
import {withRouter} from 'react-router-dom'
import GoBackLayout from "../../layouts/GoBackLayout/GoBackLayout";
import BasicThead from "../../shared-components/Tables/BasicThead/BasicThead";
import {getMyProIncomeReq} from "../../apis/goApis";

class MyProIncome extends React.Component {
    constructor(props) {
        super(props)
        this.uid = LocalStorageService.get('userid')
        this.state = {
            p: 0,
            end: false,
            list: [],
        }
        this.tHead = [
            {
                title: '时间', dataIndex: 0,
            },
            {
                title: '赛事', dataIndex: 1,
            },
            {
                title: '额度', dataIndex: 2,
            },
        ]
    }

    componentDidMount() {
        this.fetchPage()
    }

    fetchPage() {
        const end = this.state.end
        if (end) {
            return
        }
        getMyProIncomeReq({
            P: this.state.p,
            Uid: this.uid,
        }).then((res) => {
            const list = res.data.ok
            this.setState({
                list: [...this.state.list, ...list,],
                end: list.length < 10,
            })
        })
    }

    render() {
        const trTemplate = (this.state.list.map((item, index) => {
            return (
                <tr key={index}>
                    {this.tHead.map((head, i) => {

                        const mark = head.dataIndex

                        let value

                        if (mark === 0) {
                            value = item.Createt.slice(0, 10)
                        }

                        if (mark === 1) {
                            value = `${item.Zhuname} vs ${item.Kename}`
                        }
                        if (mark === 2) {
                            value = item.Cost
                        }

                        return <td key={i}>{value}</td>

                    })}
                    {/*<td>{item.time}</td>*/}
                    {/*<td>{item.star}</td>*/}
                    {/*<td>{item.category}</td>*/}
                    {/*<td>{item.gift}</td>*/}
                    {/*<td>{item.price}</td>*/}
                </tr>
            )
        }))
        return <GoBackLayout
            mainTitle='收入明细'
            history={this.props.history}
        >
            <table className='basic-table'>
                <BasicThead tHead={this.tHead}/>
                <tbody>
                {trTemplate}
                </tbody>
            </table>
        </GoBackLayout>
    }
}

export default withRouter(MyProIncome)